<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        *{
            padding: 0;
            margin: 0;
        }
         #test{
             position: absolute;
             height: 30px;
             width: 30px;
             background-color: red;
             /*transition: 1s;*/
             left: 0;
         }
    </style>
</head>
<body>
<div id="test"></div>
<script>
    let test =  document.getElementById('test');
    let jude = false;
    let time = '';
    window.onkeydown = function (e){
        if(e.keyCode == 68){
            if(jude == true){
                 return;
            }
            jude = true;
            let func = function (){
                test.style.left = test.offsetLeft + 10 + 'px';
               time = window.requestAnimationFrame(func)
            }
            func();
        }
    }

    window.onkeyup = function (e){
         if(e.keyCode == 68){
               jude = false
             window.cancelAnimationFrame(time)
         }
    }
</script>
</body>
</html>